<?php
/* 
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
echo "<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?>";
echo "<response>";
session_start();
if ($_SESSION['kteam_auth'] != true)
{
    $expire=time()+60*60;
    setcookie("redirector", "centre.html", $expire);
    echo "<result>Login</result>";
    echo "</response>";
    //header("Location: login.html");
    exit;
}

include("sqlconnect.php");
include("sqlgenerator.php");
$debug = false;

if ($debug) {
    echo '<debug>';
    echo 'Post parameters: ' . $_GET['producer_code'];
    echo '</debug>';
}

$centre_code = $_GET['centre_code'];
$action = $_GET['action'];

if (!is_null($action) && $action=='delete') {
    db_connect();
    $query = delete_centre($centre_code);
    if ($debug) {
        echo '<debug>';
        echo 'Query: ' . $query;
        echo '</debug>';
    }

    $result = db_query($query);
    echo "<result>Deleted</result>";
    exit;
}

db_connect();

// Query the film details from the film code
if (is_null($centre_code)) {
    $query = get_all_centres();
} else {
    $query = get_centre($centre_code);
}
if ($debug) {
    echo '<debug>';
    echo 'Query: ' . $query;
    echo '</debug>';
}
$result = db_query($query);
if ($debug) {
    echo '<debug>';
    echo 'Query Result: ' . $result;
    echo '</debug>';
}

while ($row = mysql_fetch_array($result)) {
    echo '<centre>';
    try {
        echo '<centre_id>'.$row['id'].'</centre_id>';
        echo '<centre_name>'.$row['name'].'</centre_name>';
        echo '<centre_code>'.$row['code'].'</centre_code>';
        echo '<aplh_code>'.$row['aplh_code'].'</aplh_code>';
    } catch (Exception $e) {
        echo '</centre>';
        echo "<result>Error</result>";
        echo "</response>";
    }
    echo '</centre>';
}
echo "<result>Success</result>";
echo "</response>";

?>